from flask import Flask,session,render_template,Blueprint,redirect,request
from config import Config
import re
from db import db
import os
app = Flask(__name__)
app.config.from_object(Config)
db.init_app(app)


# 注册蓝图
from views.user import user
from views.page import page

app.register_blueprint(user.ub)
app.register_blueprint(page.pb)


@app.route('/')
def index():
    return redirect('/user/login')


@app.before_request
def before_requre():
    pat = re.compile(r'^/static')
    if re.search(pat,request.path):
        return
    if request.path == "/user/login" :
        return
    if request.path == '/user/registry':
        return
    uname = session.get('username')
    if uname:
        return None

    return redirect("/user/login")

@app.route('/<path:path>')
def catch_all(path):
    return render_template('404.html')

if __name__ == '__main__':
    app.run()
